<template>
  <div class="common-warp wh100 warp-bg">
    <div class="noo">
      <a-card title="规则信息">
        <!-- <template #extra><a href="#">more</a></template> -->
        <a-form ref="formRef" :model="state.form" :rules=rules>
          <a-form-item label="规则名称" name="name">
            <a-input v-model:value="state.form.name" />
          </a-form-item>
        </a-form>
      </a-card>
    </div>
    <a-button type="primary" block @click="confirm(formRef)">提交</a-button>
  </div>
</template>

<script lang='ts' setup>
import { ref, reactive, onMounted, } from 'vue';
import { useRouter } from 'vue-router'
import { useAccessAreaCreateApi } from '@/api/index'
import { message } from 'ant-design-vue';


const router = useRouter()
const formRef = ref();

const rules = {
  name: [{ required: true, message: '请输入规则名称', trigger: 'change' }],
};

const useContent = () => {
  return {
    name: "",
  }
}

const state = reactive({
  form: useContent()
})

//提交
const confirm = (formRef: any) => {
  if (!formRef) return;
  formRef.validate().then(async () => {
    await useAccessAreaCreateApi(state.form)
    message.success("操作成功",2);
    setTimeout(() => {
      router.push({ name: 'AccessArea' })
    }, 2300)
  })
};

onMounted(() => {
  document.title = '新增'
})

</script>
<style scoped lang='less'>
.noo {
  height: calc(100vh - 56px);
  overflow-y: scroll;

  :deep(.ant-form-item-label) {
    padding: 0 !important;
  }

  :deep(.ant-card-body) {
    padding: 12px !important;
  }

  :deep(.ant-card-head) {
    padding: 12px !important;
  }

  :deep(.ant-form-item) {
    margin-bottom: 12px !important;
  }

}
</style>